package com.fare.fdc.action;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Namespace;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.fare.taluo.BaseFdcAction;
import com.fare.taluo.application.fetl.FreightMonitorApplication;
import com.fare.taluo.application.freight.FreightMonitorShowsApplication;
import com.fare.taluo.application.plane.city.PortApplication;
import com.fare.taluo.auth.security.ContextLoginUser;
import com.fare.taluo.auth.security.LogonUserCertificate;
import com.fare.taluo.util.DateJsonValueProcessor;
import com.fare.taluo.util.DateUtils;
import com.fare.taluo.util.I18nUtil;
import com.fare.taluo.util.StringUtils;
import com.fare.taluo.util.XmlUtil;
import com.fare.taluo.vo.fetl.FreightMonitorChartVO;
import com.fare.taluo.vo.fetl.FreightMonitorVO;
import com.fare.taluo.vo.freight.FreightMonitorSettingsVO;
import com.fare.taluo.vo.freight.FreightMonitorShowsVO;

/*
 * @xiaozhi
 * Email:ganhongzhi@foreveross.com
 * this is 运价监控设置 Action
 */
@Controller("freightMonitorShowsAction")
@Namespace("/")
@Scope("prototype")
public class FreightMonitorShowsAction extends BaseFdcAction {
	/**
	 * 
	 */
	private static final long serialVersionUID = 6998986093789423058L;
	{
		 Locale locale = super.getLocale();
		 flightDates=I18nUtil.getProperties(locale).get("xmlutil.flighDates");
		 lowestPrice  = I18nUtil.getProperties(locale).get("xmlutil.lowestPrice");
		 hightestPrice  = I18nUtil.getProperties(locale).get("xmlutil.hightestPrice");
		 cabinTrend  = I18nUtil.getProperties(locale).get("xmlutil.cabinTrend");
		 daySeq=I18nUtil.getProperties(locale).get("xmlutil.daySeq");
		 times=I18nUtil.getProperties(locale).get("xmlutil.times");
	}
	private String flightDates;
	private String lowestPrice;
	private String hightestPrice;
	private String cabinTrend; 
	private String times;
	private String daySeq;
	
	{
		/*
		舱位走势 (航班日期："+departDates+")", 
						StringUtils.array2List(aa), chartResultVOs) + "\"}");
		ja.add("{\"xml2\":\""
				+ XmlUtil.getLowerXMLmonitor("最低价 (航班日期："+departDates+")", 
						StringUtils.array2List(aa), chartResultVOs, minPrice) + "\"}");
		ja.add("{\"xml3\":\""
				+ XmlUtil.getHighXMLmonitor("最高价 (航班日期：
		*/
	}
	private String grabDateFormat = "yyyyMMddhhmmss";
	private String grabDateFormat2 = "dd";
	@Resource(name = "freightMonitorShowsApplication")
	private FreightMonitorShowsApplication freightMonitorShowsApplication;
	@Resource(name = "portApplication")
	private PortApplication portApplication;
	@Resource(name = "freightMonitorApplication")
	private FreightMonitorApplication freightMonitorApplication;
	private List<FreightMonitorSettingsVO> citylist;
	private List<FreightMonitorVO> reightMonitorListNums;
	private List<FreightMonitorVO> reightMonitorListNumALL;
	private List<FreightMonitorVO> reightMonitorList;
	private List<FreightMonitorVO> reightMonitorListData;
	private List<FreightMonitorVO> showMaxGraNum;
	private String message;// 提示信息
	private String fromCity;
	private String toCity;
	private String opDate;
	private String departDate;
	private String createTime;
	private String toCreateTime;
	private String queryDate;
	private String toQueryDate;
	private String result;
	private String airLine;
	private Long id;
	private String hbaseKey;
	private String fromCode;
	private String toCode;
	private String areaCode;
	private String showData;
	private int cabinNumForDel;
	private int cabinNumForAdd;
	private boolean flag;
	// 舱位数
	private FreightMonitorShowsVO cabinNum;
	// 子仓变化数（较上次） num
	private FreightMonitorShowsVO cabinNumForChange;
	// 航线最低价
	private FreightMonitorShowsVO lowerPrice;
	// 航线最高价
	private FreightMonitorShowsVO heightPrice;
	// 航班号list
	private List<FreightMonitorShowsVO> frieghtLineNumbers;


	// 监控页面跳转toFreightMonitorJSP
	public String toFreightMonitorJSP() {
		LogonUserCertificate user = ContextLoginUser.getLoginUser();
		Locale locale = super.getLocale();
		String currentUsers = user.getUserName();
		try {
			citylist = freightMonitorShowsApplication.findCityList(currentUsers);
		} catch (Exception e) {
			e.printStackTrace();
		}
		I18nUtil.cityMonitorI18N(citylist, locale);
		returnPageURL = "/fare/fdc/_freightMonitorShow.jsp";
		return "dispatcher";
	}

	/**
	 * 首页第一张报表 rowkey： 抓取日期(年月日)_渠道_区域ID_起点(使用三字码)_终点(使用三字码)_起飞时间(年月日)_航班号
	 * 根据ID号和航班号（airline），查询 rowkey:起点(使用三字码)_终点(使用三字码)_航班号_抓取日期(年月日)_航班日期(年月日)
	 */
	private String qrday;
	
	private final int pagerSize = 24;//一屏显示24个
	
	public void analyseBarChart2() {
		JSONArray ja = new JSONArray();
		List<FreightMonitorChartVO> chartResultVOs = new ArrayList<FreightMonitorChartVO>();
		//按抓取时间，到天分好
		Map<String, Map<String, List<FreightMonitorVO>>> datesChartVOs = new HashMap<String, Map<String, List<FreightMonitorVO>>>();
		String tempDate = null;
		Map<String, List<FreightMonitorVO>> tempChartVOMap = null;
		List<FreightMonitorVO> tempChartVOList = null;
		FreightMonitorChartVO tempChart = null;
		Double lowerPrice = 999999999d, higherPrice = 999999999d;//用无限大值，比较出最小值
		try{
			Long ids = Long.parseLong(request.getParameter("id"));
			FreightMonitorSettingsVO lines2 = freightMonitorShowsApplication
					.getMonitorById(ids);
			String airlines = lines2.getFlightNumber();
			String hbaseKeys = lines2.getHbaseKey();
			String fromCodes = lines2.getFromCode();
			String toCodes = lines2.getToCode();
			String departDates = lines2.getDepartDateString();
			String opdates = lines2.getOpDateString();
			String[] aa = airlines.split("/");
			String[] hbaseKeyString = hbaseKeys.split("/");
			reightMonitorList = new ArrayList<FreightMonitorVO>();
			//获得所有的监控航班数据
			for (int i = 0; i < aa.length; i++) {
				String flightNumbers = aa[i];
				String airHbaseKey = hbaseKeyString[i];
				reightMonitorList.addAll(freightMonitorApplication.findByDatas(
						flightNumbers, departDates, opdates, fromCodes,
						toCodes, airHbaseKey));
			}
			
		//	if(reightMonitorList != null && !reightMonitorList.isEmpty()){
				Collections.sort(reightMonitorList,
						new Comparator<FreightMonitorVO>() {
	
							@Override
							public int compare(FreightMonitorVO o1,
									FreightMonitorVO o2) {
								return o1.getGrabDate().compareTo(
										o2.getGrabDate());
							}
	
						});
				//将其组装成监控图表的形式
				//1、先按天, 按航班分好所有航班监控对象
				for(FreightMonitorVO vo : reightMonitorList){
					tempDate = DateUtils.formatDay(vo.getGrabDate(), "yyyy-MM-dd");
					if(datesChartVOs.get(tempDate) == null){
						 tempChartVOMap = new HashMap<String,List<FreightMonitorVO>>();
						 datesChartVOs.put(tempDate, tempChartVOMap);
					}
					if(datesChartVOs.get(tempDate).get(vo.getFlightNo()) == null){
						tempChartVOList = new ArrayList<FreightMonitorVO>();
						datesChartVOs.get(tempDate).put(vo.getFlightNo(), tempChartVOList);
					}
					datesChartVOs.get(tempDate).get(vo.getFlightNo()).add(vo);
					//取得一个最高，最低价，以便图表展示时不从0开始，好看一些
					if(lowerPrice > vo.getLowerPrice()) lowerPrice = vo.getLowerPrice();
					if(higherPrice > vo.getHigherPrice()) higherPrice = vo.getHigherPrice();
				}
				//2、循环天，取出最多次数的航班监控对象作为报表的x轴坐标,某天第N次
				for(String d : datesChartVOs.keySet()){
					int maxGradNum = getMaxGrabNum(datesChartVOs.get(d));
					for(int i = 1; i < maxGradNum+1; i++){
						tempChart = new FreightMonitorChartVO(d, i);
						tempChart.setMonitorVOs(this.parseGradNumVOs(datesChartVOs.get(d), i));
						chartResultVOs.add(tempChart);
					}
				}
				//3、为了方便页面展示，截取最后面的24个
				if(chartResultVOs != null && !chartResultVOs.isEmpty()){
					Collections.sort(chartResultVOs);
					int size = new Double(chartResultVOs.size()/pagerSize).intValue()+1;
					for(int i = 0 ; i < size; i++){
						if(i == (size-1))
							this.compJsonXml(ja, lowerPrice, higherPrice, departDates, aa, chartResultVOs.subList(0, chartResultVOs.size()-i*pagerSize));
						else
							this.compJsonXml(ja, lowerPrice, higherPrice, departDates, aa, chartResultVOs.subList(chartResultVOs.size() - (i+1)*pagerSize, 
									chartResultVOs.size() - i*pagerSize));
					}
					//chartResultVOs = chartResultVOs.size() > 24 ? 
					//		chartResultVOs.subList(chartResultVOs.size()-24, chartResultVOs.size())
					//		: chartResultVOs;
				}else{
					this.compJsonXml(ja, lowerPrice, higherPrice, departDates, aa, chartResultVOs);
				}
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			super.toJSONOut(ja.toString());
			chartResultVOs = null;
			//按抓取时间，到天分好
			datesChartVOs = null;
			 tempDate = null;
			tempChartVOMap = null;
			tempChartVOList = null;
			tempChart = null;
		}
		
	}
	
	private void compJsonXml(JSONArray ja, Double lowerPrice, Double higherPrice,
			String departDates, String[] aa, List<FreightMonitorChartVO> chartResultVOs){
		int minPrice = new Double(lowerPrice).intValue() - 100 > 0 ? 
				new Double(lowerPrice).intValue() - 100 :
					new Double(lowerPrice).intValue();
		int maxPrice = new Double(higherPrice).intValue() - 100 > 0 ? 
						new Double(higherPrice).intValue() - 100 :
							new Double(higherPrice).intValue();
		ja.add("{\"xml\":\""
				+ XmlUtil.getCabinXMLmonitor(cabinTrend+"("+flightDates+departDates+")", 
						StringUtils.array2List(aa), chartResultVOs) + "\"}");
		ja.add("{\"xml2\":\""
				+ XmlUtil.getLowerXMLmonitor(lowestPrice+" ("+flightDates+departDates+")", 
						StringUtils.array2List(aa), chartResultVOs, minPrice) + "\"}");
		ja.add("{\"xml3\":\""
				+ XmlUtil.getHighXMLmonitor(hightestPrice+"("+flightDates+departDates+")", 
						StringUtils.array2List(aa), chartResultVOs, maxPrice) + "\"}");
	}
	/**
	 * 核心业务逻辑,比较出需要对比的,抓取第N次的监控航班数据集合, 该集合代表"某一天第N次”上的航班舱位柱图/最低价/最高价
	 * <p>TODO 还要根据两个比较航班的抓取时间，取最近原则，放在同一次上，
	 * 比如，A航班，B航班，C航班，29日这一天，其中A抓取了三次(抓取时间：2:00,6:00,18:00)，
	 * B抓取了五次(3:00,8:00,18:00,19:00,23:00)，C两次(5:00,19:00)，
	 * 则以B五次为准，29日这一天产生五个次数，29日第1次，29日第２次，29日第３次，29日第４次，29日第５次，
	 * C航班的29日第一次并不与B的第一次放在一个柱子内，按抓取时间最近原则，与29日第二次6:00最接近。
	 * </p>
	 * @param maps
	 * @param gradNum
	 * @return
	 */
	private List<FreightMonitorVO>  parseGradNumVOs(Map<String, List<FreightMonitorVO>> maps,
			int gradNum){
		List<FreightMonitorVO> resultList = new ArrayList<FreightMonitorVO>();
		List<FreightMonitorVO> tempList = null;
		for(String flightNo : maps.keySet()){
			tempList = maps.get(flightNo);
			if(tempList.size() >= gradNum){
				Collections.sort(tempList, new Comparator<FreightMonitorVO>() {
							@Override
							public int compare(FreightMonitorVO o1,
										FreightMonitorVO o2) {
									return o1.getGrabDate().compareTo(
											o2.getGrabDate());
						}
				});
				resultList.add(tempList.get(gradNum-1));
			}else{ //补一个负值出来，以便后面判断
				resultList.add(tempList.get(0).cloneNoneMonitorVO());
			}
		}
		return resultList;
	}
	/**
	 * 获得一组航班监控对象中，最大的一批数量
	 * @param maps　一组按天分好组的航班监控对象
	 * @return 最大的一批数量有多少个
	 */
	private int getMaxGrabNum(Map<String, List<FreightMonitorVO>> maps){
		int i = 0 ;
		for(String flightNo : maps.keySet()){
			if(maps.get(flightNo).size() > i) i = maps.get(flightNo).size();
		}
		return i;
	}
	
	@SuppressWarnings({ "unused", "rawtypes", "unchecked" })
	public void analyseBarChart() {
		JSONArray ja = new JSONArray();
		List<String> careAirlines = new ArrayList<String>();
		Map<String, Map<String, String>> data = new HashMap<String, Map<String, String>>();
		Map<String, Map<String, String>> data2 = new HashMap<String, Map<String, String>>();
		Map<String, Map<String, String>> data3 = new HashMap<String, Map<String, String>>();
		List<String> flightNoNum = new ArrayList<String>();
		List<String> numbersCount = new ArrayList<String>();
		List<Map<String, String>> dataTest = new ArrayList<Map<String, String>>();
		List<Map<String, String>> dataTest2 = new ArrayList<Map<String, String>>();
		List<Map<String, String>> dataTest3 = new ArrayList<Map<String, String>>();
		List<Integer> downHigherPirce = new ArrayList<Integer>();
		List<Integer> downLowerPirce = new ArrayList<Integer>();
		List<String> tests2 = new ArrayList<String>();
		String departDates = null;

			List<List<FreightMonitorShowsVO>> datas = new ArrayList<List<FreightMonitorShowsVO>>();
			// 获取航班号，格式：CZ333/CA222
			Long ids = Long.parseLong(request.getParameter("id"));
			FreightMonitorSettingsVO lines2 = freightMonitorShowsApplication
					.getMonitorById(ids);
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
			String airlines = lines2.getFlightNumber();
			String hbaseKeys = lines2.getHbaseKey();
			String fromCodes = lines2.getFromCode();
			String toCodes = lines2.getToCode();
			String areaCode = lines2.getAreaCode();
			departDates = lines2.getDepartDateString();
			String opdates = lines2.getOpDateString();
			String[] aa = airlines.split("/");
			String[] hbaseKeyString = hbaseKeys.split("/");
			List<String> num = new ArrayList<String>();
			List<Map> tests = new ArrayList<Map>();
			int count = 0;// XX次
			int k = 0;
			String[] getDay = new String[100];// XX天
			String tmpGrabNum2 = null;// XX天第XX次
			String[] getLine = new String[100];
			// 查询MYSQL数据库
			// Map<String, Map<String,Integer>> data=new
			// HashMap<String,Map<String, Integer>>();
			for (int i = 0; i < aa.length; i++) {
				String flightNumbers = aa[i];
				String airHbaseKey = hbaseKeyString[i];
				// System.out.println("++++++flightNumbers++++++++++"+flightNumbers);
				// System.out.println("++++++airHbaseKey+++++++++++++"+airHbaseKey);
				careAirlines.add(flightNumbers);
				reightMonitorList = freightMonitorApplication.findByData(
						flightNumbers, departDates, opdates, fromCodes,
						toCodes, airHbaseKey);
				Collections.sort(reightMonitorList,
						new Comparator<FreightMonitorVO>() {

							@Override
							public int compare(FreightMonitorVO o1,
									FreightMonitorVO o2) {
								return o1.getGrabDate().compareTo(
										o2.getGrabDate());
							}

						});
				for (FreightMonitorVO tmp : reightMonitorList) {

					Map<String, String> m = new HashMap<String, String>();
					Map<String, String> m2 = new HashMap<String, String>();
					Map<String, String> m3 = new HashMap<String, String>();
					List<String> ms = new ArrayList<String>();
					List<Map> mst = new ArrayList<Map>();
					String tmpGrabNum = DateUtils.formatDay(tmp.getGrabDate(),
							grabDateFormat) + daySeq + tmp.getGrabNum() + times;
					k++;
					// = DateUtils.formatDay(tmp.getGrabDate(),
					// grabDateFormat2)+"日第"+tmp.getGrabNum()+"次";
					getDay[k] = (DateUtils.formatDay(tmp.getGrabDate(),
							grabDateFormat2));
					getLine[k] = tmp.getFlightNo();

					if (getDay[k].equals(getDay[k - 1])
							&& getLine[k].equals(getLine[k - 1])) {
						count++;
					} else {
						count = 1;
					}

					tmpGrabNum2 = DateUtils.formatDay(tmp.getGrabDate(),
							grabDateFormat2) + daySeq + count + times;
					ms.add(String.valueOf(tmp.getCabinNum()));
					// m.put(tmp.getFlightNo(),
					// String.valueOf(tmp.getCabinNum()));
					// m2.put(tmp.getFlightNo(),String.valueOf(tmp.getLowerPrice()));
					// m3.put(tmp.getFlightNo(),
					// String.valueOf(tmp.getHigherPrice()));

					m.put(tmp.getFlightNo(), String.valueOf(tmp.getCabinNum()));
					m2.put(tmp.getFlightNo(),
							String.valueOf(tmp.getLowerPrice()));
					m3.put(tmp.getFlightNo(),
							String.valueOf(tmp.getHigherPrice()));
					flightNoNum.add(tmp.getFlightNo());

					numbersCount.add(tmpGrabNum2);
					mst.add(m);
					data.put(tmpGrabNum2, m);
					data2.put(tmpGrabNum2, m2);
					data3.put(tmpGrabNum2, m3);
					tests.add(data);
					dataTest.add(m);
					dataTest2.add(m2);
					dataTest3.add(m3);
					downLowerPirce.add((int) tmp.getLowerPrice());
					downHigherPirce.add((int) tmp.getHigherPrice());
				}

			}

		List<Long> numbersCountInt = new ArrayList<Long>();
		Map<String, String> countNumber = new HashMap<String, String>();
		List<String> numbersCountDeal = new ArrayList<String>();
		// 去重
		Set set = new HashSet();
		List newList = new ArrayList();
		for (Iterator iter = numbersCount.iterator(); iter.hasNext();) {
			Object element = iter.next();
			if (set.add(element))
				newList.add(element);
		}
		numbersCount.clear();
		numbersCount.addAll(newList);

		Collections.sort(downLowerPirce);
		Collections.sort(downHigherPirce);
		int minLower = 0;
		int minHigher = 0;

		int numbCountSize = numbersCount.size();
		if (numbersCount != null && numbCountSize > 0) {
			minLower = downLowerPirce.get(0) - 100;
			minHigher = downHigherPirce.get(0) - 100;

			String s = "{\"xml\":\""
					+ XmlUtil.getXMLmonitor(cabinTrend+"("+flightDates+departDates+")", careAirlines,
							numbersCount, dataTest) + "\"}";
			String s2 = "{\"xml2\":\""
					+ XmlUtil.getXMLmonitor2(lowestPrice+"("+flightDates+departDates+")", careAirlines,
							numbersCount, dataTest2, minLower) + "\"}";
			String s3 = "{\"xml3\":\""
					+ XmlUtil.getXMLmonitor3(hightestPrice+"("+flightDates+departDates+")", careAirlines,
							numbersCount, dataTest3, minHigher) + "\"}";
			ja.add(s);
			ja.add(s2);
			ja.add(s3);
		} else {
			// 没有数据的状态下
			String s = "{\"xml\":\""+ XmlUtil.getXMLmonitor(cabinTrend+"("+flightDates+departDates+")", careAirlines,numbersCount, dataTest) + "\"}";
//			ja.add("{\"xml\":\"isNull\"}");
			ja.add(s);
			ja.add("{\"xml2\":\"isNull\"}");
			ja.add("{\"xml3\":\"isNull\"}");
		}
		super.toJSONOut(ja.toString());
	}

	// 舱位表Action
	public void analyseBarCharts() throws IOException {
		/*int pagesize=Integer.parseInt(request.getParameter("pagesize"));
		int page=Integer.parseInt(request.getParameter("page"));
	    System.out.println("page"+page);
	    System.out.println("pagesize"+pagesize);*/
//	    
		// JSONArray tjson=new JSONArray();//form实现
		JSONObject tjson = new JSONObject();// ligerUI实现
		JsonConfig jsonConfig = new JsonConfig();
		Long ids = Long.parseLong(request.getParameter("id"));
		if (ids == null || ids < 0L) {
			return;
		}
		reightMonitorListNums = new ArrayList<FreightMonitorVO>();
		List<String> careAirlines = new ArrayList<String>();
		FreightMonitorSettingsVO lines2 = freightMonitorShowsApplication
				.getMonitorById(ids);
		String airlines = lines2.getFlightNumber();
		String hbaseKeys = lines2.getHbaseKey();
		String fromCodes = lines2.getFromCode();
		String toCodes = lines2.getToCode();
		String departDates = lines2.getDepartDateString();
		String opdates = lines2.getOpDateString();
		String[] aa = airlines.split("/");// 存储航线
		String[] hbaseKeyString = hbaseKeys.split("/");
		for (int i = 0; i < aa.length; i++) {
			String flightNumbers = aa[i];
			String airHbaseKey = hbaseKeyString[i];
			careAirlines.add(flightNumbers);
			reightMonitorListNums.addAll(freightMonitorApplication.findByDatas(
					flightNumbers, departDates, opdates, fromCodes, toCodes,
					airHbaseKey));
		}
	//	if (reightMonitorListNums != null && reightMonitorListNums.size() > 0) {
			Collections.sort(reightMonitorListNums, new Comparator<FreightMonitorVO>() {
							@Override
							public int compare(FreightMonitorVO o1,
									FreightMonitorVO o2) {
								return o1.getFlightNo().compareTo(o2.getFlightNo()) == 0 ? 
										o2.getGrabDate().compareTo(o1.getGrabDate()) : o1.getFlightNo().compareTo(o2.getFlightNo());
							}

						});
			jsonConfig.registerJsonValueProcessor(Date.class,
					new DateJsonValueProcessor("yyyy-MM-dd"));
			tjson.put("Rows",
					JSONArray.fromObject(reightMonitorListNums, jsonConfig)
							.toString());
	//	}
		showData = tjson.toString();
		HttpServletResponse response = ServletActionContext.getResponse();
		response.setContentType("text/html;charset=utf-8");
		response.getWriter().write(showData);
	}

	public static void main(String[] args) {
		List<String> strList = new ArrayList<String>();
		String[] Str = new String[] { "291", "281", "283", "112", "301", "012",
				"052", "012" };
		for (int i = 0; i < Str.length; i++) {
			strList.add(Str[i]);
		}
		// System.out.println("strList1"+strList);
		// Collections.sort(strList);
		// System.out.println("strList2"+strList);
		TreeSet set = new TreeSet();
		set.add(strList);
		// System.out.println("set:"+set);

	}
	//判断是否执行刷新
	public void  reloadOR() throws IOException{
		int m=0;//判断监控的航班号有多少个为空数据
		int getAllsize=0;//数据库中有多少个舱位数的数据个数
		int tmp=0;//辅助统计有多少个柱子统计，木有实际意义
		int sizeN=0;//有多少根柱子
		Map<String, Integer> showDateAndNum=new HashMap<String , Integer>();
		List<Integer>saveAllsize =new ArrayList<Integer>(); 
		JSONArray jsb = new JSONArray();
		result="fail";//传入前端JSP，判断是否执行前端请求（success：Y，fail：N）
		Long ids = Long.parseLong(request.getParameter("id"));
		Long maxGrabNum = Long.parseLong(request.getParameter("maxGrabNum"));
		FreightMonitorSettingsVO lines2 = freightMonitorShowsApplication.getMonitorById(ids);
		String airlines = lines2.getFlightNumber();
		String hbaseKeys = lines2.getHbaseKey();
		String fromCodes = lines2.getFromCode();
		String toCodes = lines2.getToCode();
		String departDates = lines2.getDepartDateString();
		String opdates = lines2.getOpDateString();
		String[] aa = airlines.split("/");
		String[] hbaseKeyString = hbaseKeys.split("/");
		reightMonitorList = new ArrayList<FreightMonitorVO>();
		//获得所有的监控航班数据
		for (int i = 0; i < aa.length; i++) {
			String flightNumbers = aa[i];
			String airHbaseKey = hbaseKeyString[i];
			reightMonitorList=freightMonitorApplication.findByDatas(
					flightNumbers, departDates, opdates, fromCodes,
					toCodes, airHbaseKey);
			if(reightMonitorList.size()==0){
				m++;
			}
			/*int tmpT=(reightMonitorList.size())/pagerSize+1;*/
			else{
			for(FreightMonitorVO vo:reightMonitorList){
					saveAllsize.add(vo.getCabinNum());
					tmp++;
					String tmpGrabNum = DateUtils.formatDay(vo.getGrabDate(),grabDateFormat2) + daySeq + vo.getGrabNum() + times;
					showDateAndNum.put(tmpGrabNum, tmp);
					}
				}
			}
		
		sizeN=showDateAndNum.keySet().size();
		getAllsize=saveAllsize.size();
		int pingShu=sizeN/pagerSize+1;
		int otherAdd=pingShu*m;
		//getAllsize=getAllsize+otherAdd;
//		System.out.println("maxGrabNum_jsp=="+maxGrabNum);
//		System.out.println("pingShu=="+pingShu);
//		System.out.println("getAllsize="+getAllsize);
//		System.out.println("sizeN=="+sizeN);
//		System.out.println("m="+m);
		
		//跟前台JSP传过来的数据进行对比，判断是否执行加载操作
		if(getAllsize!=maxGrabNum){
			result="success";
		}
		String s = "{\"doIt\":\""+ result + "\"}";
		jsb.add(s);
		super.toJSONOut(jsb.toString());
		//return "dispatcher";
	}

	public List<FreightMonitorSettingsVO> getCitylist() {
		return citylist;
	}

	public List<FreightMonitorVO> getReightMonitorListNums() {
		return reightMonitorListNums;
	}

	public void setReightMonitorListNums(
			List<FreightMonitorVO> reightMonitorListNums) {
		this.reightMonitorListNums = reightMonitorListNums;
	}

	public List<FreightMonitorVO> getReightMonitorListNumALL() {
		return reightMonitorListNumALL;
	}

	public void setReightMonitorListNumALL(
			List<FreightMonitorVO> reightMonitorListNumALL) {
		this.reightMonitorListNumALL = reightMonitorListNumALL;
	}

	public void setCitylist(List<FreightMonitorSettingsVO> citylist) {
		this.citylist = citylist;
	}

	public List<FreightMonitorVO> getReightMonitorList() {
		return reightMonitorList;
	}

	public void setReightMonitorList(List<FreightMonitorVO> reightMonitorList) {
		this.reightMonitorList = reightMonitorList;
	}

	public FreightMonitorShowsApplication getFreightMonitorShowsApplication() {
		return freightMonitorShowsApplication;
	}

	public void setFreightMonitorShowsApplication(
			FreightMonitorShowsApplication freightMonitorShowsApplication) {
		this.freightMonitorShowsApplication = freightMonitorShowsApplication;
	}

	public String getQrday() {
		return qrday;
	}

	public void setQrday(String qrday) {
		this.qrday = qrday;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public String getFromCity() {
		return fromCity;
	}

	public void setFromCity(String fromCity) {
		this.fromCity = fromCity;
	}

	public String getToCity() {
		return toCity;
	}

	public void setToCity(String toCity) {
		this.toCity = toCity;
	}

	public String getOpDate() {
		return opDate;
	}

	public void setOpDate(String opDate) {
		this.opDate = opDate;
	}

	public String getDepartDate() {
		return departDate;
	}

	public void setDepartDate(String departDate) {
		this.departDate = departDate;
	}

	public String getCreateTime() {
		return createTime;
	}

	public void setCreateTime(String createTime) {
		this.createTime = createTime;
	}

	public String getToCreateTime() {
		return toCreateTime;
	}

	public void setToCreateTime(String toCreateTime) {
		this.toCreateTime = toCreateTime;
	}

	public String getQueryDate() {
		return queryDate;
	}

	public void setQueryDate(String queryDate) {
		this.queryDate = queryDate;
	}

	public String getToQueryDate() {
		return toQueryDate;
	}

	public void setToQueryDate(String toQueryDate) {
		this.toQueryDate = toQueryDate;
	}

	public String getResult() {
		return result;
	}

	public void setResult(String result) {
		this.result = result;
	}

	public String getAirLine() {
		return airLine;
	}

	public void setAirLine(String airLine) {
		this.airLine = airLine;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public FreightMonitorShowsVO getCabinNum() {
		return cabinNum;
	}

	public void setCabinNum(FreightMonitorShowsVO cabinNum) {
		this.cabinNum = cabinNum;
	}

	public FreightMonitorShowsVO getCabinNumForChange() {
		return cabinNumForChange;
	}

	public void setCabinNumForChange(FreightMonitorShowsVO cabinNumForChange) {
		this.cabinNumForChange = cabinNumForChange;
	}

	public FreightMonitorShowsVO getLowerPrice() {
		return lowerPrice;
	}

	public void setLowerPrice(FreightMonitorShowsVO lowerPrice) {
		this.lowerPrice = lowerPrice;
	}

	public FreightMonitorShowsVO getHeightPrice() {
		return heightPrice;
	}

	public void setHeightPrice(FreightMonitorShowsVO heightPrice) {
		this.heightPrice = heightPrice;
	}

	public List<FreightMonitorShowsVO> getFrieghtLineNumbers() {
		return frieghtLineNumbers;
	}

	public void setFrieghtLineNumbers(
			List<FreightMonitorShowsVO> frieghtLineNumbers) {
		this.frieghtLineNumbers = frieghtLineNumbers;
	}

	public String getHbaseKey() {
		return hbaseKey;
	}

	public void setHbaseKey(String hbaseKey) {
		this.hbaseKey = hbaseKey;
	}

	public String getFromCode() {
		return fromCode;
	}

	public void setFromCode(String fromCode) {
		this.fromCode = fromCode;
	}

	public String getToCode() {
		return toCode;
	}

	public void setToCode(String toCode) {
		this.toCode = toCode;
	}

	public String getAreaCode() {
		return areaCode;
	}

	public void setAreaCode(String areaCode) {
		this.areaCode = areaCode;
	}

	public PortApplication getPortApplication() {
		return portApplication;
	}

	public void setPortApplication(PortApplication portApplication) {
		this.portApplication = portApplication;
	}

	public FreightMonitorApplication getFreightMonitorApplication() {
		return freightMonitorApplication;
	}

	public void setFreightMonitorApplication(
			FreightMonitorApplication freightMonitorApplication) {
		this.freightMonitorApplication = freightMonitorApplication;
	}

	public String getShowData() {
		return showData;
	}

	public void setShowData(String showData) {
		this.showData = showData;
	}

	public int getCabinNumForDel() {
		return cabinNumForDel;
	}

	public void setCabinNumForDel(int cabinNumForDel) {
		this.cabinNumForDel = cabinNumForDel;
	}

	public int getCabinNumForAdd() {
		return cabinNumForAdd;
	}

	public void setCabinNumForAdd(int cabinNumForAdd) {
		this.cabinNumForAdd = cabinNumForAdd;
	}
	public List<FreightMonitorVO> getShowMaxGraNum() {
		return showMaxGraNum;
	}
	public void setShowMaxGraNum(List<FreightMonitorVO> showMaxGraNum) {
		this.showMaxGraNum = showMaxGraNum;
	}
	public List<FreightMonitorVO> getReightMonitorListData() {
		return reightMonitorListData;
	}
	public void setReightMonitorListData(
			List<FreightMonitorVO> reightMonitorListData) {
		this.reightMonitorListData = reightMonitorListData;
	}
	public boolean isFlag() {
		return flag;
	}
	public void setFlag(boolean flag) {
		this.flag = flag;
	}
	

}
